package com.treasure.mall.biz.entity.integral;

import com.treasure.mall.biz.entity.BasePO;
import com.treasure.mall.biz.entity.embeddable.ReceivingInfo;
import com.treasure.mall.biz.entity.user.UserPO;
import com.treasure.mall.zbq.common.ienum.order.OrderEnums;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import javax.persistence.*;
import java.math.BigDecimal;

/**
 * @author allan
 * @version 1.0.0
 * @date 2020/8/22
 */
@Entity
@Table(name = "zb_integral_order")
@Setter
@Getter
public class IntegralOrderPO extends BasePO {
    @Id
    @Column(name = "id")
    private String id;
    /**
     * 兑换用户
     */
    @ManyToOne
    @JoinColumn(name = "rel_user_id")
    private UserPO userPO;
    private Product product;
    @Column(name = "num")
    private int num;
    @Column(name = "total_integral")
    private long totalIntegral;
    @Column(name = "final_integral")
    private long finalIntegral;
    /**
     * 收货地址{@link ReceivingInfo}
     */
    private ReceivingInfo receivingInfo;
    /**
     * 优惠了多少积分
     */
    @Column(name = "pmt_integral")
    private long pmtIntegral;
    @Column(name = "deliver_status")
    private OrderEnums.DeliverStatus deliverStatus;
    @Column(name = "express_no")
    private String expressNo;
    @Column(name = "express_company")
    private String expressCompany;

    @Embeddable
    @Setter
    @Getter
    @NoArgsConstructor
    public static class Product {
        @Column(name = "product_id")
        private Long id;
        @Column(name = "product_title")
        private String title;
        /**
         * 市场价格
         */
        @Column(name = "product_price", scale = 2, precision = 10)
        private BigDecimal price;
        /**
         * 所需积分
         */
        @Column(name = "product_integral")
        private long integral;
        /**
         * 缩略图
         */
        @Column(name = "thumbnail")
        private String thumbnail;

        public Product(IntegralProductPO productPO) {
            this.id = productPO.getId();
            this.title = productPO.getTitle();
            this.price = productPO.getPrice();
            this.integral = productPO.getIntegral();
            this.thumbnail = productPO.getThumbnail();
        }
    }
}
